﻿// ===============================================================================
// XCI.NET 西安交通信息WinForm开发框架 2018 版权所有
// ===============================================================================
using System;
using System.Globalization;
using System.Windows.Forms;
using XCI.Helper;
using XCI.Windows.Controls;
using XCI.Windows.Helper;

namespace XCI.Windows.Forms
{
    [FormCaption(false)]
    public partial class FrmException : FrmBase
    {
        public FrmException()
        {
            InitializeComponent();
        }

        public FrmException(Exception e)
        {
            InitializeComponent();
            this.ExceptionInfo = e;
        }

        /// <summary>
        /// 头部控件
        /// </summary>
        protected CaptionControl FormCaptionControl => captionControl1;

        /// <summary>
        /// 异常对象
        /// </summary>
        public Exception ExceptionInfo { get; set; }

        private void ExceptionForm_Load(object sender, EventArgs e)
        {
            WinHelper.SetDateFormat(editCreateDateTime, true);
            WinHelper.ForEachPanel(panel1, p => p.BackColor = this.BackColor);
            editIP.Text = NetHelper.GetLocalIP();
            editCreateDateTime.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            editDetails.Text = DebugHelper.BuildExceptionInfo(ExceptionInfo);
        }

        private void btnCopyMessage_Click(object sender, EventArgs e)
        {
            Clipboard.SetText(editDetails.Text);
            MessageBoxHelper.ShowMessage("异常信息已经复制到剪贴板!");
        }

        private void btnFeedback_Click(object sender, EventArgs e)
        {
            MessageBoxHelper.ShowMessage("信息已经反馈,工作人员会尽快修复为,感谢您的支持!");
            this.Close();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}